#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef int ElemType;
int m; //m为操作次数
typedef struct LNode {
    ElemType data; //结点的数据域
    struct LNode *next; //结点的指针域
}LNode, *LinkList; //LinkList为指向结构体LNode的指针类型

void CreateList_H(LinkList &L, int n){
    L = new LNode;
    L->next = NULL;
    while(n--){
        LNode *p = new LNode;
        cin >> p->data;
        p->next = L->next;
        L->next = p;
    }
}
Status GetElem(LinkList L, int i, ElemType &e){
    int j = 1;
    LNode *p = L->next;
    while(j < i && p){
        p = p->next;
        j++;
    }
    if(p){
        e = p->data;
        return OK;
    }
    return ERROR;
}
LNode *LocateElem(LinkList L, ElemType e){
    LNode *p = L->next;
    while(p && p->data != e){
        p = p->next;
    }
    return p;
}
Status ListInsert(LinkList &L, int i, ElemType e){
    int j = 1;
    LNode *p = L;
    while(j < i && p){
        p = p->next;
        j++;
    }
    if(p){
        LNode *q = new LNode;
        q->data = e;
        q->next = p->next;
        p->next = q;
        return OK;
    }
    return ERROR;
}
Status ListDelete(LinkList &L, int i){
    int j = 1;
    LNode *p = L;
    while(j < i && p->next){
        p = p->next;
        j++;
    }
    if(p){
        LNode *q = p->next;
        p->next = q->next;
        delete q;
        return OK;
    }
    return ERROR;
}

void Out_list(LinkList L){//输出单链表
    LinkList p;
    p = L->next;
    while (p){
        cout <<p->data<<' ';
        p = p->next;
    }
    cout<<endl;
}

int main() {
    LinkList L,q;
    ElemType e;
    int i,temp,n;

    cin >> m;     //m次操作
    while(m --) {
        char op;
        cin >> op;
        switch(op){
            case 'C'://创建单链表
                cin>>n;
                CreateList_H(L, n);
                Out_list(L);
                break;
            case 'G'://取元素
                cin>>i;
                temp = GetElem(L,i,e);
                if (temp != 0){
                     cout <<e<<endl;
                }
                break;
            case 'S'://查找元素
                cin>>e;
                q = LocateElem(L, e);
                if (q) {
                    cout<<q->data<<endl;
                }
                break;
            case 'I'://插入元素
                cin>>i;
                cin>>e;
                ListInsert(L, i, e);
                Out_list(L);
                break;
            case 'D'://删除元素
                cin>>i;
                ListDelete(L, i);
                Out_list(L);
                break;
        }
    }
    return 0;
}
